home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module 3- drawing text / source / animalpane.java next >
Encoding:
Java Source  |  2000-06-23  |  5.3 KB  |  135 lines

  1. import java.io.IOException;
  2. import java.io.FileNotFoundException;
  3.  
  4. import quicktime.app.QTFactory;
  5. import quicktime.app.anim.Compositor;
  6. import quicktime.app.image.GraphicsImporterDrawer; 
  7. import quicktime.app.image.ImagePresenter; 
  8. import quicktime.app.image.ImageUtil;
  9. import quicktime.app.players.MoviePresenter;
  10.  
  11. import quicktime.io.QTFile;
  12. import quicktime.io.OpenMovieFile;
  13.  
  14. import quicktime.qd.QDRect;
  15. import quicktime.qd.QDGraphics;
  16. import quicktime.qd.QDColor; 
  17. import quicktime.qd.QDConstants; 
  18.  
  19. import quicktime.std.StdQTConstants;
  20. import quicktime.std.movies.Movie; 
  21.  
  22. import quicktime.QTSession;
  23. import quicktime.QTException; 
  24.  
  25. /**
  26.  * QTZoo Module 2 - Playing a movie
  27.  *
  28.  * @author Michael Hopkins
  29.  * @author Levi Brown
  30.  * @author Apple Computer, Inc.
  31.  * @version 1.0.1 11/15/1999
  32.  *
  33.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  34.  *    
  35.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  36.  *                ("Apple") in consideration of your agreement to the following terms, and your
  37.  *                use, installation, modification or redistribution of this Apple software
  38.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  39.  *                please do not use, install, modify or redistribute this Apple software.
  40.  *
  41.  *                In consideration of your agreement to abide by the following terms, and subject
  42.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  43.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  44.  *                reproduce, modify and redistribute the Apple Software, with or without
  45.  *                modifications, in source and/or binary forms; provided that if you redistribute
  46.  *                the Apple Software in its entirety and without modifications, you must retain
  47.  *                this notice and the following text and disclaimers in all such redistributions of
  48.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  49.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  50.  *                Apple Software without specific prior written permission from Apple.  Except as
  51.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  52.  *                are granted by Apple herein, including but not limited to any patent rights that
  53.  *                may be infringed by your derivative works or by other works in which the Apple
  54.  *                Software may be incorporated.
  55.  *
  56.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  57.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  58.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  59.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  60.  *                COMBINATION WITH YOUR PRODUCTS.
  61.  *
  62.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  63.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  64.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  65.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  66.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  67.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  68.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  69.  *
  70.  * Revision History
  71.  * ---------------------------------------------------------------------------------
  72.  * 12/02/99 MSH  cleaned up code, added comments
  73.  * 
  74.  */
  75. public class AnimalPane
  76. {
  77.     /**
  78.      *  Public default constructor
  79.      *  Creates the map button, and sets up the listeners
  80.      */
  81.     public AnimalPane()
  82.     {
  83.         QDRect size = new QDRect(Zoo2.WIDTH, Zoo2.HEIGHT);
  84.     
  85.         try
  86.         {
  87.             QDGraphics gw = new QDGraphics( size );            // create a new graphics object
  88.             
  89.             compositor = new Compositor( gw, QDColor.white, 30, 1 );
  90.  
  91.             QTFile imageFile = new QTFile( 
  92.                 QTFactory.findAbsolutePath( "data/zebra/ZebraBackground.jpg" ));
  93.             GraphicsImporterDrawer drawer = new GraphicsImporterDrawer( imageFile );
  94.             
  95.             ImagePresenter presenter = ImagePresenter.fromGraphicsImporterDrawer( drawer );
  96.             presenter.setLocation( 110, 110 );                // set location of movie within compositor
  97.             compositor.addMember( presenter, 2 );            // add image presenter to compositor in 2nd layer
  98.  
  99.             Movie m = makeMovie( new QTFile( 
  100.                 QTFactory.findAbsolutePath( "data/zebra/Zebra.mov" )));
  101.             md = new MoviePresenter( m );                    // create presenter from movie file    
  102.             compositor.addMember( md, 1 );                    // add presenter to compositor
  103.             compositor.getTimer().setRate(1);                // start compositor
  104.             md.setRate(1);                                    // start movie
  105.         }
  106.         catch ( IOException e )                                // catch any errors
  107.         {
  108.             e.printStackTrace();
  109.         }
  110.         catch ( QTException e )
  111.         {
  112.             e.printStackTrace();
  113.         }
  114.     }
  115.  
  116.     public Compositor getCompositor( ) { return compositor; }    // returns the compositor associated with the animal pane
  117.             
  118.  
  119.     /**
  120.      * Opens the movie file and sets it up to be played.
  121.      * @param f a QTFile representing the movie to initialize.
  122.      * @return the movie, ready to play
  123.      */
  124.     protected Movie makeMovie( QTFile f ) throws IOException, QTException
  125.     {
  126.         OpenMovieFile movieFile = OpenMovieFile.asRead(f);
  127.         Movie m = Movie.fromFile( movieFile );
  128.         m.getTimeBase().setFlags( StdQTConstants.loopTimeBase );// we want the movie to loop    
  129.         return m;    
  130.     }
  131.     
  132.     protected Compositor compositor;
  133.     protected MoviePresenter md;
  134. }
  135.